package com.hrms.doctor.controller;

import com.hrms.patient.core.controller.BaseController;
import com.hrms.patient.core.domain.AjaxResult;
import com.hrms.doctor.domain.Message;
import com.hrms.doctor.domain.vo.MessageVo;
import com.hrms.doctor.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Api(tags = "留言信息接口")
@RestController

public class MessageController extends BaseController {
    @Autowired
    MessageService messageService;
    //新增
    @ApiOperation("新增医生留言")
    @PostMapping("/message/doctor")
    public AjaxResult insertMessage(@Validated @RequestBody Message message){
        return toAjax(messageService.insertDoctorMessage(message));
    }

    @ApiOperation("新增患者留言")
    @PostMapping("/message/patient")
    public AjaxResult insertPatientMessage(@Validated @RequestBody Message message){
        return toAjax(messageService.insertPatientMessage(message));
    }
    //获取全部留言
    //1->患者获取医生消息，2->医生获取自己消息，3->医生获取患者消息,4->患者获取自己消息
   // @ApiOperation("获取留言")
   /* @GetMapping("/messages")
    public AjaxResult selectMessageBy(Long doctorId,Long patientId,int opt){
        //TODO:TOKENID
        return success(messageService.selectMessage(doctorId,patientId,opt));
    }*/
    @GetMapping("/message")
    @ApiOperation("获取留言")
    public AjaxResult get(Long doctorId,Long patientId){
        List<MessageVo> list=messageService.getMessage(doctorId,patientId);
        return success(list);
    }






    //撤回
    @ApiOperation("撤回消息")
    @DeleteMapping("/messages")
    public AjaxResult delete(Long doctorId, Long patientId,@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")  LocalDateTime createTime){
        return toAjax(messageService.delete(doctorId,patientId,createTime));
    }
    //医生获取未读消息数
    @ApiOperation("获取医生未读数目")
    @GetMapping("/messages/countPatient")
    public AjaxResult selectMessageByDoctor(){
        return success(messageService.countPatient());
    }
    //患者获取未读消息数
    @ApiOperation("获取患者未读数目")
    @GetMapping("/messages/countDoctor")
    public AjaxResult selectMessageByPatient(){
        return success(messageService.countDoctor());
    }
}
